<template>
  <SuperTable ref="superTableRef" search pager border align="center" :columns="columns" :data-request="fetchData" :export-config="{}" header-title="历史库存" />
</template>

<script setup lang="ts">
import SuperTable from '@/framework/components/core/super-table/super-table.vue';
import { VxeGridPropTypes } from 'vxe-table';
import type { TableColumnItem } from './columns';
import { baseColumns } from './columns';
import { ref } from 'vue';
import { stockHistorySearch } from '@/api/store/stock_history_data';

/**
 * table
 */
const superTableRef = ref<InstanceType<typeof SuperTable>>();
const columns: TableColumnItem[] = baseColumns;
const fetchData = async (ori: VxeGridPropTypes.ProxyAjaxQueryParams) => {
  let data = superTableRef.value?.getFormModel();
  let params = {
    pageSize: ori.page.pageSize,
    pageNum: ori.page.currentPage,
    orderBy: [
      {
        field: 'createTime',
        order: 'desc',
      },
    ],
    ...data,
  };
  // 时间处理
  data.inTimeBtw ? (params.inTimeBtw = data.inTimeBtw.join() + ' 23:59:59') : delete params.inTimeBtw;
  data.outTimeBtw ? (params.outTimeBtw = data.outTimeBtw.join() + ' 23:59:59') : delete params.outTimeBtw;
  let res = await stockHistorySearch(params);
  return res.result;
  // return {
  //   data: [{}, {}, {}],
  //   pageIndex: 1,
  //   pageSize: 10,
  //   total: 100,
  // };
};
// const refreshTableFn = () => {
//   superTableRef.value?.refreshTable();
// };
</script>

<style scoped lang="less"></style>
